package com.ruoyi.base.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.lang3.StringUtils;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.base.domain.ProcedureClassify;
import com.ruoyi.base.service.IProcedureClassifyService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 工序分类Controller
 * 
 * @author ruoyi
 * @date 2022-08-17
 */
@RestController
@RequestMapping("/base/ProcedureClassify")
public class ProcedureClassifyController extends BaseController {
    @Autowired
    private IProcedureClassifyService procedureClassifyService;

    /**
     * 查询工序分类列表
     */
    @PreAuthorize("@ss.hasPermi('base:ProcedureClassify:list')")
    @GetMapping("/list")
    public TableDataInfo list(ProcedureClassify procedureClassify) {
        startPage();
        List<ProcedureClassify> list = procedureClassifyService.selectProcedureClassifyList(procedureClassify);
        return getDataTable(list);
    }

    /**
     * 导出工序分类列表
     */
    @PreAuthorize("@ss.hasPermi('base:ProcedureClassify:export')")
    @Log(title = "工序分类", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ProcedureClassify procedureClassify)
    {
        List<ProcedureClassify> list = procedureClassifyService.selectProcedureClassifyList(procedureClassify);
        ExcelUtil<ProcedureClassify> util = new ExcelUtil<ProcedureClassify>(ProcedureClassify.class);
        util.exportExcel(response, list, "工序分类数据");
    }

    /**
     * 获取工序分类详细信息
     */
    @PreAuthorize("@ss.hasPermi('base:ProcedureClassify:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(procedureClassifyService.selectProcedureClassifyById(id));
    }

    /**
     * 新增工序分类
     */
    @PreAuthorize("@ss.hasPermi('base:ProcedureClassify:add')")
    @Log(title = "工序分类", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ProcedureClassify procedureClassify) {
        if (StringUtils.isBlank(procedureClassify.getProcedureClassifyName())){
            return AjaxResult.error("工序分类名称不能为空！");
        }
        return toAjax(procedureClassifyService.insertProcedureClassify(procedureClassify));
    }

    /**
     * 修改工序分类
     */
    @PreAuthorize("@ss.hasPermi('base:ProcedureClassify:edit')")
    @Log(title = "工序分类", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ProcedureClassify procedureClassify)
    {
        return toAjax(procedureClassifyService.updateProcedureClassify(procedureClassify));
    }

    /**
     * 删除工序分类
     */
    @PreAuthorize("@ss.hasPermi('base:ProcedureClassify:remove')")
    @Log(title = "工序分类", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(procedureClassifyService.deleteProcedureClassifyByIds(ids));
    }
}
